package com.tulingxueyuan.order.service.impl;

import com.tulingxueyuan.order.api.StockService;
import com.tulingxueyuan.order.mapper.OrderMapper;
import com.tulingxueyuan.order.pojo.Order;
import com.tulingxueyuan.order.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/**
 * @Author li
 * @Date 2025/4/26 17:28
 * @description: TODO
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private StockService stockService;

    @GlobalTransactional
    @Override
    public Order create(Order order) {
        // 能否插入成功？
        orderMapper.insert(order);

        // 扣减库存，能否成功？
        String msg = stockService.reduce(order.getProductId());
        // 异常
        int a = 1 / 0;
        return order;
    }
}
